<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>设备档案</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<style type="text/css">
		.left-label {
			width: 100px !important
		}
	</style>
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<div class="demoTable" style="padding:10px 0 0 15px">
	<div class="layui-inline">
		<%--
			<input class="layui-input" name="searchTime" id="searchTime" placeholder="请输入时间检索" style="display: inline; width: 45%">
		--%>
		<input class="layui-input" name="keyword" id="keyword" placeholder="请输入设备名称" autocomplete="off" style="display: inline; width: 100%">
	</div>
	<button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">搜索</i></button>
</div>
<table class="layui-hide" id="tableList" lay-filter="tableList"></table>
<table class="layui-hide" id="tableList1" lay-filter="tableList1"></table>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="add"><i class="layui-icon layui-icon-add-1">新增</i></button>
		<button class="layui-btn layui-btn-blue" lay-event="delete"><i class="layui-icon layui-icon-delete">批量删除</i></button>
	</div>
</script>

<script type="text/html" id="rowToolbar">
	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>

<script type="text/javascript">
    layui.use(['table','layer','upload','form','laydate'], function(){
        var table = layui.table;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var form = layui.form;

        var $ = layui.jquery, active = {
            reload:function () {
                /*var searchTime = $("#searchTime").val();*/
                var keyword01 = $("#keyword").val();
                /*console.log(searchTime + ',' + keyword)*/
                table.reload('contenttable',{
                    method:'get',
                    where:{"keyword01":keyword01}
                });
            }
        }
        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //设备台帐信息
        table.render({
            elem: '#tableList'
            ,url:'${pageContext.request.contextPath }/deviceFile/queryDeviceFile.do'
            //,toolbar: '#toolbar'
            ,title: '设备台帐信息'
            ,id :'contenttable'
            ,limits:[10,20,30]
            ,cols: [[
                {type: 'checkbox', fixed: 'left'},
                {field:'id', title:'ID', fixed: 'left', unresize: true, sort: true, align:'center', type:'numbers'},
                {field:'deviceName', title:'设备名称'},
                {field:'deviceNo', title:'设备编号'},
                {field:'deviceVersion', title:'设备型号'},
                {field:'useLocation', title:'使用地点'},
                {field:'outTime', title:'出厂日期'},
                {field:'useTime', title:'使用日期'},
                {field:'manufacturers', title:'设备生产厂家'},
                {field:'op1', title:'附属设备明细', templet:function (rowData){
                    return "<a href='javascript:void(0)' style='color:#4D61B3' onclick='attachDeviceEvent(\""+rowData.id+"\")'>"+'查看详细'+"</a>";
                }},
                {field:'op2', title:'检修', templet:function (rowData){
                	return "<a href='javascript:void(0)' style='color:#4D61B3' onclick='overhaulEvent(\""+rowData.id+"\")'>"+'查看详细'+"</a>";
                }},
                {field:'op3', title:'润滑', templet:function (rowData){
                    return "<a href='javascript:void(0)' style='color:#4D61B3' onclick='lubricateEvent(\""+rowData.id+"\")'>"+'查看详细'+"</a>";
				}},
                //{field: 'right', title:'操作', toolbar: '#rowToolbar'}
            ]],
            page: true
        });
        //设备维修申请表登记
        table.render({
            elem: '#tableList1'
            ,url:'${pageContext.request.contextPath }/maintResume/queryMaintenanceRecord.do'
            /* ,toolbar: '#toolbarDemo' */
            ,title: '设备维修申请表登记'
            /* ,id :'contenttable' */
            ,limits:[10,20,30]
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID', fixed: 'left', unresize: true, sort: true, type:'numbers'}
                ,{field:'deviceName', title:'设备名称'}
                ,{field:'deviceNo', title:'设备编号'}
                ,{field:'deviceVersion', title:'设备型号'}
                ,{field:'maintainType', title:'保养类别'}
                ,{field:'maintainCycle', title:'保养周期'}
                ,{field:'maintainTime', title:'保养时间'}
                ,{field:'maintainResult', title:'保养结果'}
                ,{field:'maintainRemark', title:'备注'}
                ,{field:'op1', title:'保养项目', templet:function (rowData){
                    return "<a href='javascript:void(0)' style='color:#4D61B3' onclick='maintenanceRecordDetailEvent(\""+rowData.id+"\")'>"+'查看详细'+"</a>";
                }}
                /* ,{field: 'right', title:'操作', toolbar: '#rowToolbar', align: 'center'} */
            ]]
            ,page: true
        });
        
        //头工具栏事件
        table.on('toolbar(tableList)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    layer.open({
                        type: 1 					//Page层类型
                        ,area: ['750px', '450px'] 	//宽  高
                        ,title: '新增'
                        ,shade: 0.6 				//遮罩透明度
                        ,maxmin: true 				//允许全屏最小化
                        ,anim: 1 					//0-6的动画形式，-1不开启
                        ,content: '<form class="layui-form" id="addFormID">'+
                        '<div style="border: 1px solid #E6E6E6; margin: 15px 15px;">'+
	                        '<table>'+
	                        '<tr>'+
	                        	'<td><label class="layui-form-label" style="margin-left:-10px; margin-top:9px">设备编号</label></td>&nbsp;'+
	                        	'<td>'+
		                        	'<div class="layui-input-block" style="width: 230px; margin-top: 10px; margin-left:26px">'+
										'<select class="layui-select" id="deviceNo" name="deviceNo" lay-filter="displayInfo" lay-verify="deviceNo">'+
											'<option value="">请选择</option>'+
										'</select>'+
									'</div>'+
	                        	'</td>'+
			                    '<td><label class="layui-form-label" style="margin-left:-10px; margin-top:9px">设备名称</label></td>'+
			                    '<td><input class="layui-input" type="text" id="deviceName" name="deviceName" style="width:230px; margin-top:10px; margin-left:-2px; display: inline;"></td>'+
	                        '</tr>'+
	                        '</table>'+
							'&emsp;&emsp;设备型号&emsp;&emsp;&emsp;<input class="layui-input" id="deviceVersion" name="deviceVersion" lay-verify="deviceVersion" type="text" style="width:230px; margin-top:15px; display: inline;">'+
							'&emsp;&emsp;使用地点&emsp;<input class="layui-input" id="useLocation" name="useLocation" lay-verify="useLocation" type="text" lay-verify="email" style="width:230px; display: inline;"><br>'+
							'&emsp;&emsp;设备出厂日期&emsp;<input class="layui-input" id="outTime" name="outTime" lay-verify="outTime" type="text" style="width:230px; margin-top:15px; display: inline;">'+
							'&emsp;&emsp;使用日期&emsp;<input class="layui-input" id="useTime" name="useTime" lay-verify="useTime" type="text" style="width:230px; display: inline;"><br>'+
							'&emsp;&emsp;设备生产厂家&emsp;<input class="layui-input" id="manufacturers" name="manufacturers" lay-verify="manufacturers" type="text" style="width:558px; margin-top:15px; margin-bottom: 15px; display: inline;"><br>'+
                        '</div>'+
                        '&emsp;&emsp;<span style="margin-top: 30px;">附属设备明细</span>&emsp;<br>'+
                        '<div style="border: 1px solid #E6E6E6; margin: 15px 15px;">'+
							'<div style="width: 60px; height: 30px; margin-left: 60px; margin-top: 15px; float: left;">名称</div>'+
							'<div style="width: 60px; height: 30px; margin-left: 70px; margin-top: 15px; float: left;">规格型号</div>'+
							'<div style="width: 60px; height: 30px; margin-left: 80px; margin-top: 15px; float: left;">性能参数</div>'+
							'<div style="width: 60px; height: 30px; margin-left: 90px; margin-top: 15px; float: left;">数量</div>'+
							'<div style="width: 60px; height: 30px; margin-left: 70px; margin-top: 15px; float: left;">单位</div><br>'+

							'<input class="layui-input" id="attachDeviceName1" name="attachDeviceName" lay-verify="attachDeviceName" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceVersion1" name="attachDeviceVersion" lay-verify="attachDeviceVersion" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceParam1" name="attachDeviceParam" lay-verify="attachDeviceParam" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceCount1" name="attachDeviceCount" lay-verify="attachDeviceCount" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceUnit1" name="attachDeviceUnit" lay-verify="attachDeviceUnit" type="text" style="width:100px; margin-left: 20px; margin-top:5px; display: inline;">'+

							'<input class="layui-input" id="attachDeviceName2" name="attachDeviceName" lay-verify="attachDeviceName" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceVersion2" name="attachDeviceVersion" lay-verify="attachDeviceVersion" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceParam2" name="attachDeviceParam" lay-verify="attachDeviceParam" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceCount2" name="attachDeviceCount" lay-verify="attachDeviceCount" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceUnit2" name="attachDeviceUnit" lay-verify="attachDeviceUnit" type="text" style="width:100px; margin-left: 20px; margin-top:5px; display: inline;">'+

							'<input class="layui-input" id="attachDeviceName3" name="attachDeviceName" lay-verify="attachDeviceName" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceVersion3" name="attachDeviceVersion" lay-verify="attachDeviceVersion" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceParam3" name="attachDeviceParam" lay-verify="attachDeviceParam" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceCount3" name="attachDeviceCount" lay-verify="attachDeviceCount" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceUnit3" name="attachDeviceUnit" lay-verify="attachDeviceUnit" type="text" style="width:100px; margin-left: 20px; margin-top:5px; display: inline;">'+

							'<input class="layui-input" id="attachDeviceName4" name="attachDeviceName" lay-verify="attachDeviceName" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceVersion4" name="attachDeviceVersion" lay-verify="attachDeviceVersion" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceParam4" name="attachDeviceParam" lay-verify="attachDeviceParam" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceCount4" name="attachDeviceCount" lay-verify="attachDeviceCount" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceUnit4" name="attachDeviceUnit" lay-verify="attachDeviceUnit" type="text" style="width:100px; margin-left: 20px; margin-top:5px; display: inline;">'+

							'<input class="layui-input" id="attachDeviceName5" name="attachDeviceName" lay-verify="attachDeviceName" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceVersion5" name="attachDeviceVersion" lay-verify="attachDeviceVersion" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceParam5" name="attachDeviceParam" lay-verify="attachDeviceParam" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceCount5" name="attachDeviceCount" lay-verify="attachDeviceCount" type="text" style="width:120px; margin-left: 20px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="attachDeviceUnit5" name="attachDeviceUnit" lay-verify="attachDeviceUnit0" type="text" style="width:100px; margin-left: 20px; margin-top:5px; margin-bottom:10px; display: inline;">'+
                        '</div>'+
                        '&emsp;&emsp;<span style="margin-top: 30px;">检修</span>&emsp;<br>'+
                        '<div style="border: 1px solid #E6E6E6; margin: 15px 15px;">'+
							/*'&emsp;&emsp;检修周期&emsp;&emsp;&emsp;'+
							'&emsp;大修&emsp;<input class="layui-input" type="text" style="width:130px; margin-top: 15px; display: inline;">'+
							'&emsp;中修&emsp;<input class="layui-input" type="text" style="width:130px; display: inline;">'+
							'&emsp;小修&emsp;<input class="layui-input" type="text" style="width:130px; margin-bottom: 15px; display: inline;"><br>'+*/

							'<div style="width: 80px; height: 30px; margin-left: 60px; margin-top: 15px; float: left;">检修周期</div>'+
							'<div style="width: 60px; height: 30px; margin-left: 125px; margin-top: 15px; float: left;">大修</div>'+
							'<div style="width: 60px; height: 30px; margin-left: 120px; margin-top: 15px; float: left;">中修</div>'+
							'<div style="width: 60px; height: 30px; margin-left: 95px; margin-top: 15px; float: left;">小修</div><br>'+
							'<input class="layui-input" id="overhaulCycle1" name="overhaulCycle" lay-verify="overhaulCycle" type="text" style="width:128px; margin-left: 27px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="bigOverhaul1" name="bigOverhaul" lay-verify="bigOverhaul" type="text" style="width:128px; margin-left: 60px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="midOverhaul1" name="midOverhaul" lay-verify="midOverhaul" type="text" style="width:128px; margin-left: 55px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="smallOverhaul1" name="smallOverhaul" lay-verify="smallOverhaul" type="text" style="width:128px; margin-left: 27px; margin-top:5px; display: inline;"><br>'+

							'<input class="layui-input" id="overhaulCycle2" name="overhaulCycle" lay-verify="overhaulCycle" type="text" style="width:128px; margin-left: 27px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="bigOverhaul2" name="bigOverhaul" lay-verify="bigOverhaul" type="text" style="width:128px; margin-left: 60px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="midOverhaul2" name="midOverhaul" lay-verify="midOverhaul" type="text" style="width:128px; margin-left: 55px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="smallOverhaul2" name="smallOverhaul" lay-verify="smallOverhaul" type="text" style="width:128px; margin-left: 27px; margin-top:5px; margin-bottom:15px; display: inline;"><br>'+
						'</div>'+
						'&emsp;&emsp;<span style="margin-top: 30px;">润滑</span>&emsp;<br>'+
						'<div style="border: 1px solid #E6E6E6; margin: 15px 15px;">'+
							'<div style="width: 80px; height: 30px; margin-left: 60px; margin-top: 15px; float: left;">润滑油名称</div>'+
							'<div style="width: 60px; height: 30px; margin-left: 125px; margin-top: 15px; float: left;">规格</div>'+
							'<div style="width: 60px; height: 30px; margin-left: 120px; margin-top: 15px; float: left;">用量(L)</div>'+
							'<div style="width: 60px; height: 30px; margin-left: 95px; margin-top: 15px; float: left;">备注</div><br>'+
							'<input class="layui-input" id="lubricateOilName1" name="lubricateOilName" lay-verify="lubricateOilName" type="text" style="width:128px; margin-left: 27px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="lubricateVersion1" name="lubricateVersion" lay-verify="lubricateVersion" type="text" style="width:128px; margin-left: 60px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="lubricateML1" name="lubricateML" lay-verify="lubricateML" type="text" style="width:128px; margin-left: 55px; margin-top:5px; display: inline;">'+
							'<input class="layui-input" id="lubricateRemark1" name="lubricateRemark" lay-verify="lubricateRemark" type="text" style="width:128px; margin-left: 27px; margin-top:5px; display: inline;"><br>'+

							'<input class="layui-input" id="lubricateOilName2" name="lubricateOilName" lay-verify="lubricateOilName" type="text" style="width:128px; margin-left: 27px; margin-top:5px; margin-bottom:15px; display: inline;">'+
							'<input class="layui-input" id="lubricateVersion2" name="lubricateVersion" lay-verify="lubricateVersion" type="text" style="width:128px; margin-left: 60px; margin-top:5px; margin-bottom:15px; display: inline;">'+
							'<input class="layui-input" id="lubricateML2" name="lubricateML" lay-verify="lubricateML" type="text" style="width:128px; margin-left: 55px; margin-top:5px; margin-bottom:15px; display: inline;">'+
							'<input class="layui-input" id="lubricateRemark2" name="lubricateRemark" lay-verify="lubricateRemark" type="text" style="width:128px; margin-left: 27px; margin-top:5px; margin-bottom:15px; display: inline;"><br>'+
                        '</div>'+
                        '<button class="layui-btn layui-btn-blue" lay-submit lay-filter="addForm" style="margin-left:250px; margin-top: 25px; margin-bottom: 25px">立即提交</button>'+
                        '&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary">重置</button></form>'
                        ,success: function(){
                            //设备出厂日期
                            laydate.render({
                                elem: '#outTime',
                                type: 'datetime'
                            });
                            //使用日期
                            laydate.render({
                                elem: '#useTime',
                                type: 'datetime'
                            });
                            
                            $.ajax({
    			  	            type: 'POST',
    			  	            url: '${pageContext.request.contextPath}/device/queryAllDeviceList.do',
    			  	            dataType: 'json',
    			  	            async: false,
    			  	            success: function (data){
    			  	                for (var i = 0; i < data.length; i++) {
    			  	                    $("#deviceNo").append("<option value='"+ data[i].deviceNo +"'>"+ data[i].deviceNo +"</option>");
    			  	                }
    			  	            }
    			  	        });
                            form.render();
                        }
                    });
                break;
                //批量删除
                case 'delete':
                    var data = checkStatus.data;
                    var idArr = new Array();
                    if(data.length==0){
                        toastr.warning("请至少选择一条记录！");
                    }
                    for(var i=0;i<data.length;i++){
                        idArr[i] = data[i].id;
                    }
                    $.ajax({
                        type:'post',
                        url:'${pageContext.request.contextPath }/deviceFile/deleteDeviceFileById.do',
                        data:{"idArr" : idArr},
                        success:function(data){
                            layer.confirm('确定删除吗？', function(index){
                                if(data > 0){
                                    toastr.success("删除成功！");
                                    location.reload();
                                    /*setTimeout(function(){
                                        //使用setTimeout（）方法设定定时2000毫秒
                                        //关闭模态框
                                        //父页面刷新
                                        window.location.reload();
                                    },2000);*/
                                }else{
                                    toastr.warning("删除失败！");
                                    location.reload();
                                }
                            });
                        }
                    });
                break;
            };
        });

        //监听行工具事件
        table.on('tool(tableList)', function(obj){
            var data = obj.data;
            //console.log(data);
            var idArr = new Array();
            /*console.log(obj)*/
            //单个删除
            if(obj.event === 'del'){
                layer.confirm('确定删除吗？', function(index){
                    var id = obj.data.id;
                    idArr[0] = id;
                    $.ajax({
                        type:'post',
                        url:'${pageContext.request.contextPath }/deviceFile/deleteDeviceFileById.do',
                        data:{ "idArr" : idArr },
                        success:function(data){
                            if(data > 0){
                                toastrStyle();
                                toastr.success("删除成功！");
                                setTimeout(function(){
                                    location.reload();
                                },1000);
                                /*setTimeout(function(){
                                    //关闭模态框
                                    //父页面刷新
                                    window.location.reload();
                                },2000);*/
                            }else{
                                toastrStyle();
                                toastr.warning("删除失败！");
                                setTimeout(function(){
                                    location.reload();
                                },1000);
                            }
                        }
                    })
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.open({
                    type: 1 					//Page层类型
                    ,area: ['40%', '70%'] 		//宽  高
                    ,title: '编辑'
                    ,shade: 0.6 				//遮罩透明度
                    ,maxmin: true 				//允许全屏最小化
                    ,anim: 1 					//0-6的动画形式，-1不开启
                    ,content: '<form class="layui-form" id="editFormID">'+
                    	'<table>'+
                    		'<tr>'+
                    			'<td><input class="layui-hide" id="id" name="id" value="'+data.id+'"></td>'+
                    		'<tr>'+
                    		'<tr>'+
	                    		'<td><label class="layui-form-label left-label" style="margin-top:20px">设备编号</label></td>'+
                    			'<td>'+
									'<div class="layui-input-block" style="width: 150px; margin-left: 0px; margin-top:20px">'+
					           			'<select class="layui-select" id="deviceNo" name="deviceNo" lay-filter="displayInfo" lay-verify="deviceNo">'+
					                   		'<option value="">请选择</option>'+
					                   	'</select>'+
					                '</div>'+
		            			'</td>'+
                    			'<td><label class="layui-form-label left-label" style="margin-top:20px">设备名称</label></td>'+
                    			'<td><input class="layui-input" id="deviceName" name="deviceName" value="'+data.deviceName+'" lay-verify="deviceName" style="width:150px; margin-top:20px"></td>'+
                    		'<tr>'+
                    		'<tr style="height:20px"></tr>'+
                    		'<tr>'+
                				'<td><label class="layui-form-label left-label">设备型号</label></td>'+
                				'<td><input class="layui-input" id="deviceVersion" name="deviceVersion" value="'+data.deviceVersion+'" lay-verify="deviceVersion" style="width:150px"></td>'+
                				'<td><label class="layui-form-label left-label">使用地点</label></td>'+
                				'<td><input class="layui-input" id="useLocation" name="useLocation" value="'+data.useLocation+'" lay-verify="useLocation" style="width:150px"></td>'+
                			'<tr>'+
                			'<tr style="height:20px"></tr>'+
                			'<tr>'+
            					'<td><label class="layui-form-label left-label">出厂日期</label></td>'+
            					'<td><input class="layui-input" id="outTime" name="outTime" value="'+data.outTime+'" lay-verify="outTime" style="width:150px"></td>'+
            					'<td><label class="layui-form-label left-label">使用日期</label></td>'+
            					'<td><input class="layui-input" id="useTime" name="useTime" value="'+data.useTime+'" lay-verify="useTime" style="width:150px"></td>'+
            				'<tr>'+
            				'<tr style="height:20px"></tr>'+
            				'<tr>'+
        						'<td><label class="layui-form-label left-label">设备生产厂家</label></td>'+
        						'<td><input class="layui-input" id="manufacturers" name="manufacturers" value="'+data.manufacturers+'" lay-verify="manufacturers" style="width:150px"></td>'+
        						'<td></td>'+
        						'<td></td>'+
        					'<tr>'+
        					'<tr style="height:20px"></tr>'+
        					'<tr>'+
    							'<td colspan="2"><button class="layui-btn layui-btn-blue" lay-submit lay-filter="editForm" style="margin-left:160px; margin-bottom: 20px">立即提交</button></td>'+
    							'<td colspan="2">&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px">重置</button></td>'+
    						'<tr>'+
    					'</table>'+
                    '</form>'
                    ,success: function(){
                        //出厂日期
                        laydate.render({
                            elem: '#outTime',
                            type: 'datetime'
                        });
                        //使用日期
                        laydate.render({
                            elem: '#useTime',
                            type: 'datetime'
                        });
                      	//下拉框查找所有设备
			  			$.ajax({
			  	            type: 'POST',
			  	            url: '${pageContext.request.contextPath}/device/queryAllDeviceList.do',
			  	            dataType: 'json',
			  	            async: false,
			  	            success: function (datas){
                                for (var i = 0; i < datas.length; i++) {
                                    $("#deviceNo").append("<option value='"+ datas[i].deviceNo +"'>"+ datas[i].deviceNo +"</option>");
                                    if(datas[i].deviceNo == data.deviceNo){
                                        $("#deviceNo").val(data.deviceNo);
                                    }
                                }
			  	            }
			  	        });
                      form.render();
                    }
                });
            }
        });

        /**
         * 通用表单提交(AJAX方式)(新增)
         */
        form.on('submit(addForm)', function (data) {
            $.ajax({
                url : '${pageContext.request.contextPath}/deviceFile/addDeviceFile.do',
                data: $("#addFormID").serialize(),
                cache : false,
                type : "post",
            }).done(
                function(res) {
                    if (res > 0) {
                        toastrStyle();
                        toastr.success('添加成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function(res) {
                    toastrStyle();
                    toastr.error('添加失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        });
        /**
         * 通用表单提交(AJAX方式)(修改)
         */
        form.on('submit(editForm)', function (data) {
            $.ajax({
                url : '${pageContext.request.contextPath}/deviceFile/editDeviceFileById.do',
                data: $("#editFormID").serialize(),
                cache : false,
                type : "post",
            }).done(
                function(res) {
                    if (res > 0) {
                        toastrStyle();
                        toastr.success('修改成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function(res) {
                    toastrStyle();
                    toastr.error('修改失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        });

        //出厂日期
        laydate.render({
            elem: '#outTime1',
            type: 'datetime'
        });
        //使用日期
        laydate.render({
            elem: '#useTime1',
            type: 'datetime'
        });
        /**
         * 新增表单校验
         */
        form.verify({
            //value：表单的值item：表单的DOM对象
            deviceName: function(value, item){
                if(value == ''){
                    return '设备名称字段不能为空';
                }
            },
            deviceNo: function(value, item){
                if(value == ''){
                    return '设备编号字段不能为空';
                }
            },
            deviceVersion: function(value, item){
                if(value == ''){
                    return '型号字段不能为空';
                }
            },
            useLocation: function(value, item){
                if(value == ''){
                    return '使用地点字段不能为空';
                }
            },
            outTime2: function(value, item){
                if(value == ''){
                    return '出厂日期字段不能为空';
                }
            },
            useTime2: function(value, item){
                if(value == ''){
                    return '使用日期字段不能为空';
                }
            },
            manufactures: function(value, item){
                if(value == ''){
                    return '设备生产厂家字段不能为空';
                }
            }
        });
        
        form.on('select(displayInfo)', function(data){
        	$.ajax({
                type: 'POST',
                url: '${pageContext.request.contextPath}/device/queryDeviceInfoByNo.do',
                data: {deviceNo:$('#deviceNo').val()},
                /* dataType: 'json', */
                /* async: false, */
                success: function (data){
                	var device = eval('(' +data+ ')');
                	$('#deviceName').val(device.deviceName);
                	$('#deviceVersion').val(device.deviceVersion);
                	$('#manufacturers').val(device.manufacturers);
                	$('#outTime').val(device.outTime);
                }
            });
        });
    });
    toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
    //提示框样式
    function toastrStyle(){
        toastr.options = {
            "closeButton": false,
            "debug": false,
            "newestOnTop": false,
            "progressBar": false,
            "positionClass": "toast-top-center",
            "preventDuplicates": false,
            "onclick": null,
            "showDuration": "5000",
            "hideDuration": "1000",
            "timeOut&quot": "100000",
            "extendedTimeOut": "0",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };
    }

    //附属设备明细
    function attachDeviceEvent(dId){
        layer.open({
            type: 1 					//Page层类型
            ,area: ['500px', '450px']   //宽  高
            ,title: '附属设备明细'
            ,shade: 0.6 				//遮罩透明度
            ,maxmin: true 			    //允许全屏最小化
            ,anim: 1 					//0-6的动画形式，-1不开启
            /* ,content: $("#lookupTable2") */
            ,content: '<table class="layui-hide" id="lookupTable1" lay-filter="lookupTable1"></table>'
            ,success: function(){
                layui.use(['table'], function(){
                    var table = layui.table;
                    table.render({
                        elem: '#lookupTable1'
                        ,url:'${pageContext.request.contextPath }/deviceFile/queryAttachDetailById.do?dId='+dId
                        /*,where:{dId:thisRowId.id}*/
                        /*,toolbar: '#toolbar'*/
                        ,title: '附属设备明细'
                        ,id :'contenttable'
                        ,limits:[10,20,30]
                        ,cols: [[
                            /*{type: 'checkbox', fixed: 'left'},*/
                            {field:'id', title:'ID', fixed: 'left', unresize: true, sort: true, type:'numbers'},
                            {field:'attachDeviceName', title:'附属设备名称'},
                            {field:'attachDeviceVersion', title:'附属设备规格型号'},
                            {field:'attachDeviceParam', title:'附属设备性能参数'},
                            {field:'attachDeviceCount', title:'附属设备数量'},
                            {field:'attachDeviceUnit', title:'附属设备单位'}
                        ]]
                        ,page: false
                    });
                    //行单击事件
                    /* table.on('row(lookupTable2)', function(obj){
                      alert("单击事件")
                    }); */
                    //行双击事件
                    /*table.on('rowDouble(lookupTable1)', function(rowData){
                        console.log(rowData.data.uaddress);
                        layer.closeAll();
                        $("#deviceName").val(rowData.data.uaddress);
                        $("#deviceNo").val(rowData.data.uname);
                    });*/
                });
            }
        });
    }

    //检修
	function overhaulEvent(dId){
        layer.open({
            type: 1 					//Page层类型
            ,area: ['500px', '450px']   //宽  高
            ,title: '润滑'
            ,shade: 0.6 				//遮罩透明度
            ,maxmin: true 			    //允许全屏最小化
            ,anim: 1 					//0-6的动画形式，-1不开启
            /* ,content: $("#lookupTable2") */
            ,content: '<table class="layui-hide" id="lookupTable1" lay-filter="lookupTable1"></table>'
            ,success: function(){
                layui.use(['table'], function(){
                    var table = layui.table;
                    table.render({
                        elem: '#lookupTable1'
                        ,url:'${pageContext.request.contextPath }/deviceFile/queryDeviceFileOverhaulById.do?dId='+dId
                        /*,where:{dId:thisRowId.id}*/
                        /*,toolbar: '#toolbar'*/
                        ,title: '检修'
                        ,id :'contenttable'
                        ,limits:[10,20,30]
                        ,cols: [[
                            /*{type: 'checkbox', fixed: 'left'},*/
                            {field:'id', title:'ID', fixed: 'left', unresize: true, sort: true, type:'numbers'},
                            {field:'overhaulCycle', title:'检修周期'},
                            {field:'bigOverhaul', title:'大修'},
                            {field:'midOverhaul', title:'中修'},
                            {field:'smallOverhaul', title:'小修'}
                        ]]
                        ,page: false
                    });
                    //行单击事件
                    /* table.on('row(lookupTable2)', function(obj){
                      alert("单击事件")
                    }); */
                    //行双击事件
                    /*table.on('rowDouble(lookupTable1)', function(rowData){
                        console.log(rowData.data.uaddress);
                        layer.closeAll();
                        $("#deviceName").val(rowData.data.uaddress);
                        $("#deviceNo").val(rowData.data.uname);
                    });*/
                });
            }
        });
	}

	//润滑
    function lubricateEvent(dId){
        layer.open({
            type: 1 					//Page层类型
            ,area: ['500px', '450px']   //宽  高
            ,title: '润滑'
            ,shade: 0.6 				//遮罩透明度
            ,maxmin: true 			    //允许全屏最小化
            ,anim: 1 					//0-6的动画形式，-1不开启
            /* ,content: $("#lookupTable2") */
            ,content: '<table class="layui-hide" id="lookupTable1" lay-filter="lookupTable1"></table>'
            ,success: function(){
                layui.use(['table'], function(){
                    var table = layui.table;
                    table.render({
                        elem: '#lookupTable1'
                        ,url:'${pageContext.request.contextPath }/deviceFile/queryAttachDetailById.do?dId='+dId
                        /*,where:{dId:thisRowId.id}*/
                        /*,toolbar: '#toolbar'*/
                        ,title: '润滑'
                        ,id :'contenttable'
                        ,limits:[10,20,30]
                        ,cols: [[
                            /*{type: 'checkbox', fixed: 'left'},*/
                            {field:'id', title:'ID', fixed: 'left', unresize: true, sort: true, type:'numbers'},
                            {field:'attachDeviceName', title:'润滑油名称'},
                            {field:'attachDeviceVersion', title:'规格'},
                            {field:'attachDeviceParam', title:'用量(L)'},
                            {field:'attachDeviceCount', title:'备注'}
                        ]]
                        ,page: false
                    });
                    //行单击事件
                    /* table.on('row(lookupTable2)', function(obj){
                      alert("单击事件")
                    }); */
                    //行双击事件
                    /*table.on('rowDouble(lookupTable1)', function(rowData){
                        console.log(rowData.data.uaddress);
                        layer.closeAll();
                        $("#deviceName").val(rowData.data.uaddress);
                        $("#deviceNo").val(rowData.data.uname);
                    });*/
                });
            }
        });
	}
	
  //根据申请表ID查询保养详细
    function maintenanceRecordDetailEvent(mId){
    	layer.open({
            type: 1 					//Page层类型
            ,area: ['500px', '450px']   //宽  高
            ,title: '保养项目明细'
            ,shade: 0.6 				//遮罩透明度
            ,maxmin: true 			    //允许全屏最小化
            ,anim: 1 					//0-6的动画形式，-1不开启
            /* ,content: $("#lookupTable2") */
            ,content: '<table class="layui-hide" id="lookupTable1" lay-filter="lookupTable1"></table>'
            ,success: function(){
                layui.use(['table'], function(){
                    var table = layui.table;
                    table.render({
                        elem: '#lookupTable1'
                        ,url:'${pageContext.request.contextPath }/maintResume/queryMaintenanceRecordDetailById.do?mId='+mId
                        /*,where:{dId:thisRowId.id}*/
                        /*,toolbar: '#toolbar'*/
                        ,title: '保养项目明细'
                        ,id :'contenttable'
                        ,limits:[10,20,30]
                        ,cols: [[
                            /*{type: 'checkbox', fixed: 'left'},*/
                            {field:'id', title:'ID', fixed: 'left', unresize: true, sort: true, type:'numbers'},
                            {field:'maintainItem', title:'保养项目'},
                            {field:'remark', title:'结果'},
                            {field:'result', title:'备注'}
                        ]]
                        ,page: false
                    });
                    //行单击事件
                    /* table.on('row(lookupTable2)', function(obj){
                      alert("单击事件")
                    }); */
                    //行双击事件
                    /*table.on('rowDouble(lookupTable1)', function(rowData){
                        console.log(rowData.data.uaddress);
                        layer.closeAll();
                        $("#deviceName").val(rowData.data.uaddress);
                        $("#deviceNo").val(rowData.data.uname);
                    });*/
                });
            }
        });
    }
</script>

</body>
</html>